# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import xadmin
from xadmin import views
from xadmin.views.website import LoginView

from fs.models import *
from pbx.models import *
from .models import webPost


class LoginViewAdmin(LoginView):
    title = 'SoftcoIPPbx管理系统'

# Register your models here.
class GlobalSettings(object):
    site_title = u"SoftcoIPPbx"
    site_footer = u"江苏聚欣科技股份有限公司"
    #菜单
    def get_site_menu(self):
        return (
            {
                'title': '电话管理',
                'icon': 'fa fa-phone',
                'menus': (
                    {
                        'title': '在线分机',
                        'icon': 'fa fa-laptop',
                        'url': self.get_model_url(regdn, 'changelist')
                    },
                    {
                        'title': '号码管理',
                        'icon': 'fa fa-mobile',
                        'url': self.get_model_url(SipUser, 'changelist')
                    },
                    {
                        'title': '局内路由',
                        'icon': 'fa fa-road',
                        'url': self.get_model_url(LocalExtension, 'changelist')
                    },
                    {
                        'title': '入局路由',
                        'icon': 'fa fa-road',
                        'url': self.get_model_url(PublicExtension, 'changelist')
                    },
                    {
                        'title': '出局路由',
                        'icon': 'fa fa-road',
                        'url': self.get_model_url(CallOutExtension, 'changelist')
                    },
                )
            },
            {
                'title': '网络配置',
                'icon': 'fa fa-signal',
                'menus': (
                    {
                        'title': 'SIP网关',
                        'icon': 'fa fa-rss',
                        'url': self.get_model_url(SipPro, 'changelist')
                    },
                    {
                        'title': '访问控制(ACL)',
                        'icon': 'fa fa-rss',
                        'url': self.get_model_url(ACL, 'changelist')
                    },
                )
            },
            {
                'title': '业务配置',
                'icon': 'fa fa-sitemap',
                'menus': (
                    {
                        'title': '电话分组',
                        'icon': 'fa fa-group',
                        'url': self.get_model_url(group, 'changelist')
                    },
                    {
                        'title': '简单IVR',
                        'icon': 'fa fa-music',
                        'url': self.get_model_url(ivr, 'changelist')
                    },
                )
            },
            {
                'title': '系统',
                'icon': 'fa fa-bars',
                'menus': (
                    {
                        'title': '系统重启',
                        'icon': 'fa fa-refresh',
                        'url': self.get_model_url(sysrestart, 'changelist')
                    },
                    {
                        'title': 'licence提交',
                        'icon': 'fa fa-file-text-o',
                        'url': self.get_model_url(licence, 'changelist')
                    },
                    {
                        'title': '常见问题',
                        'icon': 'fa fa-file-text-o',
                        'url': self.get_model_url(webPost, 'changelist')
                    },
                )
            },
        )


class webPostAdmin(object):
    is_execute = True
    #readonly_fields = ['title'] #
    #exclude['']
    #xadmin.views.edit.UpdateAdminView.exclude=['title']
    list_display = ['title', 'body', 'timestamp']  # 设置xadmin后台显示字段
    search_fields = ['title', 'body', 'timestamp']  # 设置xadmin后台搜索字段，注意：搜索字段如果有时间类型会报错
    list_filter = ['title', 'body', 'timestamp']     # 设置xadmin后台过滤器帅选字段，时间用过滤器来做
    model_icon = 'fa fa-comment-o'
    #actions = [webPostActions, ]

    def save_models(self):
        obj = self.new_obj
        obj.save()




xadmin.site.register(views.CommAdminView, GlobalSettings)
xadmin.site.register(webPost,webPostAdmin)
xadmin.site.register(LoginView, LoginViewAdmin)
#xadmin.site.register_plugin(TerminalPlugin,DeleteAdminView)
